package com.mingdong.first.factory.simpleFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.mingdong.first.factory.pizza.Pizza;

public class OrderPizza {

	
	SimplePizzaFactory simplePizzaFactory;
	
	public OrderPizza(SimplePizzaFactory simplePizzaFactory){
		setFactory(simplePizzaFactory);
	}

	
	public void setFactory(SimplePizzaFactory simplePizzaFactory){
		
		do {
			
			String type = getType();
			Pizza pizza = simplePizzaFactory.createPizza(type);
			if(pizza != null){
				pizza.prepare();
				pizza.cook();
				pizza.cut();
				pizza.box();
				
			}
		} while (true);	
		
	}
	
	
	public String getType(){
	
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String line = reader.readLine();
			return line;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "";
		}
		
	}
	
}
